--REQUIRES--

--DECLARACION DE VARIABLES GLOBALES--
charactersStateId = {}
charactersStates = {}

--DEFINICION DE FUNCIONES--

function NextEndPoint(liCharacterId)
	for i = 1, #charactersStateId do
		if liCharacterId == charactersStateId[i][1] then
			pos = i
		end
	end
	nextStateId = 1 + (charactersStateId[pos][2] % #charactersStates[pos])	
	nextPoint = charactersStates[pos][nextStateId]
	charactersStateId[pos][2] = nextStateId
	SetPatrolTarget(liCharacterId, nextPoint[1], nextPoint[2], nextPoint[3])
end

function DrawPath()
	for i = 1, #charactersStates do
		length = #charactersStates[i]
		for j = 1, length-1 do
			DrawLine(charactersStates[i][j][1],charactersStates[i][j][2],charactersStates[i][j][3],charactersStates[i][j+1][1],charactersStates[i][j+1][2],charactersStates[i][j+1][3])
		end
		DrawLine(charactersStates[i][length][1],charactersStates[i][length][2],charactersStates[i][length][3],charactersStates[i][1][1],charactersStates[i][1][2],charactersStates[i][1][3])
		DrawAwareRadius(charactersStateId[i][1])
	end
end

--CODIGO LUA--

--Llamamos desde Lua a la funcion CreatePatrol definida en C++
--para crear un personaje y asociarle un comportamiento controlado por teclado
IdPlayer=CreatePlayer(0.0, 1.0, 5.0, 1.0, 0.005)

--Llamamos desde Lua a la funcion CreatePatrol definida en C++
--para crear un personaje y asociarle un comportamiento

--Personaje1
ID=CreatePatrol(0.0, 1.0, 0.0, 1.0, 0.90,IdPlayer,2.0)
charactersStateId[1] = {ID,0}
charactersStates[1] = {{-3.0,1.0,-3.0},{-3.0,1.0,3.0},{3.0,1.0,3.0},{3.0,1.0,-3.0}}

--Personaje2
ID=CreatePatrol(0.0, 1.0, 0.0, 1.0, 0.90,IdPlayer, 1.0)
charactersStateId[2] = {ID,0}
charactersStates[2] = {{-2.5,1.0,0.0},{-5.0,1.0,-1.0},{-5.0,1.0,-5.0},{-2.5,1.0,-6.0},{0.0,1.0,-5.0},{0.0,1.0,-1.0}}

